class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def getKthFromEnd(self, head: ListNode, k: int) -> ListNode:
        if head is None:
            return None
        p = head
        q = head
        while k>0:
            q = q.next
            k -= 1
        while q:
            p = p.next
            q = q.next
        
        return p